
//  LXNetPhotoViewController.m
//  LXLessDemo
//
//  Created by LX on 16/2/13.
//  Copyright © 2016年 LX. All rights reserved.
//

#import "LXNetPhotoViewController.h"
#import "LXCustomNavView.h"
#import "LXDanmuView.h"

@interface LXNetPhotoViewController ()<UIAlertViewDelegate>
@property (strong,nonatomic) LXCustomNavView *customNavView;
@property(assign,nonatomic)CGPoint editPoint;

@end

@implementation LXNetPhotoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = backColor;
    [self addNavView];
    [self addEditImage];
//    [self settingImage:self.image];
}
-(void)addNavView{
    
    self.customNavView = [[LXCustomNavView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth([UIScreen mainScreen].bounds), 40) title:@""];
    [self.view addSubview:self.customNavView];
    //leftBarButton
    [self.customNavView settingBackBarButtonWithImage:[UIImage imageNamed:@"close"] text:nil sel:@selector(backButtonClick) target:self];
    //rightBarButton
    [self.customNavView settingRightBarButtonWithImage:nil text:@"完成" sel:@selector(nexrButtonClick) target:self];
    
}
-(void)addEditImage{

    self.editImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 40, CGRectGetWidth([UIScreen mainScreen].bounds), 320)];
    [self.editImage setUserInteractionEnabled:YES];
    [self.editImage setImage:self.image];
    [self.view addSubview:self.editImage];
    

}
-(void)settingImage:(UIImage *)image{
    self.image = image;
    [self.editImage setImage:image];
    self.editImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 40, CGRectGetWidth([UIScreen mainScreen].bounds), 320)];
    [self.editImage setUserInteractionEnabled:YES];
    [self.editImage setImage:self.image];
    [self.view addSubview:self.editImage];

}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{
    UITouch *touch = [touches anyObject];
    CGPoint touchPoint = [touch locationInView:self.view];
    NSLog(@"%f==%f",touchPoint.x,touchPoint.y);
    int stringFloat = (int)(touchPoint.x);
    int stringFloat1 = (int)(touchPoint.y);
    NSLog(@"%i%i",stringFloat,stringFloat1);
    if (touchPoint.y >= 40 && touchPoint.y < 360 ) {
        self.editPoint = touchPoint;
        UIAlertView *ale = [[UIAlertView alloc] initWithTitle:@"点击输入商品" message:nil delegate:self cancelButtonTitle:@"确认" otherButtonTitles:@"取消", nil];
        ale.alertViewStyle = UIAlertViewStylePlainTextInput;
        [ale show];
    }

}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    UITextField *te = [alertView textFieldAtIndex:0];
    if ( te.text.length > 0 && buttonIndex == 0) {
        LXDanmuView *dView = [[LXDanmuView alloc] initDanMuViewWithTypeImage:nil textBgImage:[UIImage imageNamed:@"closeX"] textString:te.text];
        dView.frame = CGRectMake(self.editPoint.x, self.editPoint.y, CGRectGetWidth(dView.bounds), CGRectGetHeight(dView.bounds));
        [self.view addSubview:dView];
    }
}
-(void)nexrButtonClick{
    NSLog(@"跳转！");
    [self dismissViewControllerAnimated:YES completion:^{
        ;
    }];

;
}

-(void)backButtonClick{
    NSLog(@"返回！");
    [self dismissViewControllerAnimated:YES completion:^{
        ;
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(BOOL)prefersStatusBarHidden{
    return YES;
}


@end
